package com.swind.fast.modules.app.railway.report.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.swind.fast.common.api.vo.Result;
import com.swind.fast.common.system.query.QueryGenerator;
import com.swind.fast.common.util.oConvertUtils;
import com.swind.fast.common.util.CommonUtils;
import com.swind.fast.common.util.MinioUtil;

import com.swind.fast.modules.app.railway.report.entity.RailwayReportTaskWorkload;
import com.swind.fast.modules.app.railway.report.service.IRailwayReportTaskWorkloadService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import lombok.extern.slf4j.Slf4j;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;

@RestController
@RequestMapping("/app/railway/hreport/task")
@Slf4j
// @Api(tags="报表模块")
@ApiSort(value = 1)
public class RailwayReportHomeController {

    @Autowired
    private IRailwayReportTaskWorkloadService railwayProjectService;

    @ApiOperationSupport(order = 99)
    // @ApiOperation("部门工作量报表 - ID查看详情")
    @GetMapping(value = "/workload/department/summary")
    public Result<?> departmentSummay(HttpServletRequest req) {
        String startDate = null, endDate = null;
        Map<String, String[]> parameterMap = req.getParameterMap();
        if (parameterMap != null && parameterMap.containsKey("startDate")) {
            startDate = parameterMap.get("startDate")[0].trim();
        }

        if (parameterMap != null && parameterMap.containsKey("endDate")) {
            endDate = parameterMap.get("endDate")[0].trim();
        }

        log.info("startDate: {}, endDate: {}", startDate, endDate);

        List<Map<String, Object>> result = railwayProjectService.getDepartmentSummary(startDate, endDate);

        return Result.OK(result);
    }

}
